﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System.IO;
using System.Xml;

namespace WorkRecorder.Business
{
    [Serializable]
    [DataContract]
    [XmlRootAttribute("WorkRecords", IsNullable = false)]
    public class Records<T> : ICloneable where T : Record    
    {
        public Records() { }

        private ObservableCollection<T> recordSet = new ObservableCollection<T>();

        [DataMember]
        [XmlElementAttribute("Record", IsNullable = false)]
        public ObservableCollection<T> RecordSet { get { return recordSet; } set { recordSet = value; } }


        public object Clone()
        {
            //MemoryStream ms = new MemoryStream();
            XmlSerializer serializer = new XmlSerializer(typeof(ObservableCollection<Record>));
           // XmlSerializer deSerializer = new XmlSerializer(typeof(ObservableCollection<Record>));

            using (MemoryStream ms = new MemoryStream())
            {
                serializer.Serialize(ms, RecordSet);
                ms.Position = 0;
                return serializer.Deserialize(ms);
            }

 
             return null;
        }
    }

}
